package org.smog.core.config.web;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 *
 * 以前是用 WebMvcConfigurerAdapter ，springboot 2.0 建议使用 WebMvcConfigurationSupport 。
 * 但是在添加拦截器并继承 WebMvcConfigurationSupport
 * 后会覆盖@EnableAutoConfiguration关于WebMvcAutoConfiguration的配置

 * @Description: Created by IntelliJ IDEA.
 * @project_name: smogTemp
 * @time: 2020-05-13 16:04
 * @email: 17685306043@163.com
 * @author: huangZhongYao
 */
@Slf4j
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        log.info("初始化静态资源目录...");

        //将所有/static/** 访问都映射到classpath:/static/ 目录下
        registry
                .addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");
        //swagger2
        registry.addResourceHandler("doc.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        //webjars
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}
